import 'package:flutter/material.dart';
import 'package:base/vm/view_model.dart';
import 'package:provider/provider.dart';

abstract class ViewModelState<T extends StatefulWidget, VM extends ViewModel>
    extends State<T> with AutomaticKeepAliveClientMixin {
  late VM fetchModel; //获取数据
  late VM model; //双向绑定
  @override
  void initState() {
    super.initState();
  }

  @override
  @mustCallSuper
  Widget build(BuildContext context) {
    fetchModel = context.read<VM>();
    model = context.watch<VM>();
    return super.build(context);
  }

  @override
  void dispose() {
    super.dispose();
    fetchModel.dispose();
    //model.dispose();
  }

  @override
  bool get wantKeepAlive => false;
}
